using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace Decision.BusinessLayer.DataLayer
{
	/// <summary>
	/// Data access layer class for ReportDecision3
	/// </summary>
	class ReportDecision3Sql : DataLayerBase 
	{

        #region Constructor

		/// <summary>
		/// Class constructor
		/// </summary>
		public ReportDecision3Sql()
		{
			// Nothing for now.
		}

        #endregion

        #region Public Methods

        /// <summary>
        /// Select by Criteria
        /// </summary>
        /// <param name="Criteria">Criteria</param>
        /// <returns>ReportDecision3 business object</returns>
        public List<ReportDecision3> SelectByObject(ReportDecision3Criteria value)
        {
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "dbo.[ReportDecision3]";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {

			if (value.StartDate.HasValue)
			{
				sqlCommand.Parameters.Add(new SqlParameter("@StartDate", value.StartDate));
			}
			if (value.EndDate.HasValue)
			{
				sqlCommand.Parameters.Add(new SqlParameter("@EndDate", value.EndDate));
			}
			if (value.PageNum > 0)
			{
				sqlCommand.Parameters.Add(new SqlParameter("@PageNum", value.PageNum));
			}
			if (value.PageSize > 0)
			{
				sqlCommand.Parameters.Add(new SqlParameter("@PageSize", value.PageSize));
			}
			if (!string.IsNullOrEmpty(value.SortName))
			{
				sqlCommand.Parameters.Add(new SqlParameter("@SortName", value.SortName));
			}
			if (!string.IsNullOrEmpty(value.SortDirection))
			{
				sqlCommand.Parameters.Add(new SqlParameter("@SortDirection", value.SortDirection));
			}
			if (!string.IsNullOrEmpty(value.VOTE_TYPE_ID))
			{
				sqlCommand.Parameters.Add(new SqlParameter("@VOTE_TYPE_ID", value.VOTE_TYPE_ID));
			}
			if (!string.IsNullOrEmpty(value.NOTICE))
			{
				sqlCommand.Parameters.Add(new SqlParameter("@NOTICE", value.NOTICE));
			}
			if (!string.IsNullOrEmpty(value.VOTE_CASE_ID))
			{
				sqlCommand.Parameters.Add(new SqlParameter("@VOTE_CASE_ID", value.VOTE_CASE_ID));
			}

                MainConnection.Open();

                IDataReader dataReader = sqlCommand.ExecuteReader();


                return PopulateObjectsFromReader(dataReader);

            }
            catch (Exception ex)
            {
                throw new Exception("ReportDecision3::SelectByObject::Error occured.", ex);
            }
            finally
            {             
                MainConnection.Close();
                sqlCommand.Dispose();
            }

        }

        #endregion

        #region Private Methods

        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(ReportDecision3 businessObject, IDataReader dataReader)
        {


				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.RowAll.ToString())))
				{
					businessObject.RowAll = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.RowAll.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.Row_No.ToString())))
				{
					businessObject.Row_No = dataReader.GetInt64(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.Row_No.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.MEMBER_NAME.ToString())))
				{
					businessObject.MEMBER_NAME = dataReader.GetString(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.MEMBER_NAME.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_1.ToString())))
				{
					businessObject.COUNT_DEC_1 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_1.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_2.ToString())))
				{
					businessObject.COUNT_DEC_2 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_2.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_3.ToString())))
				{
					businessObject.COUNT_DEC_3 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_3.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_4.ToString())))
				{
					businessObject.COUNT_DEC_4 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_4.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_5.ToString())))
				{
					businessObject.COUNT_DEC_5 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_5.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_6.ToString())))
				{
					businessObject.COUNT_DEC_6 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_6.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_7.ToString())))
				{
					businessObject.COUNT_DEC_7 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_7.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_8.ToString())))
				{
					businessObject.COUNT_DEC_8 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_8.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_9.ToString())))
				{
					businessObject.COUNT_DEC_9 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_9.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_10.ToString())))
				{
					businessObject.COUNT_DEC_10 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_10.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_11.ToString())))
				{
					businessObject.COUNT_DEC_11 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_11.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_12.ToString())))
				{
					businessObject.COUNT_DEC_12 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_12.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_13.ToString())))
				{
					businessObject.COUNT_DEC_13 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_13.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_14.ToString())))
				{
					businessObject.COUNT_DEC_14 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_14.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_15.ToString())))
				{
					businessObject.COUNT_DEC_15 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_15.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_16.ToString())))
				{
					businessObject.COUNT_DEC_16 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_16.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_17.ToString())))
				{
					businessObject.COUNT_DEC_17 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_17.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_18.ToString())))
				{
					businessObject.COUNT_DEC_18 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_18.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_19.ToString())))
				{
					businessObject.COUNT_DEC_19 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_19.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_20.ToString())))
				{
					businessObject.COUNT_DEC_20 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_20.ToString()));
				}

				if (!dataReader.IsDBNull(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_21.ToString())))
				{
					businessObject.COUNT_DEC_21 = dataReader.GetInt32(dataReader.GetOrdinal(ReportDecision3.ReportDecision3Fields.COUNT_DEC_21.ToString()));
				}


        }

        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of ReportDecision3</returns>
        internal List<ReportDecision3> PopulateObjectsFromReader(IDataReader dataReader)
        {

            List<ReportDecision3> list = new List<ReportDecision3>();

            while (dataReader.Read())
            {
                ReportDecision3 businessObject = new ReportDecision3();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return list;

        }

        #endregion

	}
}
